//package com.gylang.auth.acpect;
//
//import com.gylang.auth.DTO.LoginInfoDTO;
//import com.gylang.auth.client.ProductService;
//import com.gylang.auth.config.LoginUserBeanConfig;
//import com.gylang.auth.security.OnlineUserService;
//import com.gylang.auth.utils.JsonUtils;
//import org.apache.shiro.subject.SimplePrincipalCollection;
//import org.apache.shiro.subject.support.DefaultSubjectContext;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.*;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.concurrent.TimeUnit;
//
///**
// * @author gylang,
// * @data 2019/11/21 23:12,
// * @DESC
// */
//@Component
//@Aspect
//public class SessionAspect {
//    @Autowired
//    private RedisTemplate<String, String> redisTemplate;
//    @Autowired
//    private ProductService productService;
//    @Autowired
//    LoginUserBeanConfig loginUserBeanConfig;
//
//    @Pointcut("execution(public * com.gylang.auth.controller.*.*(..))")
//    public void all() {
//    }
//
//    @AfterReturning("all()")
//    @Async
//    public void all1() {
//
//
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = attributes.getRequest();
//        String key = loginUserBeanConfig.getSessionPrefix() + request.getSession().getId();
//        SimplePrincipalCollection simplePrincipalCollection =
//                (SimplePrincipalCollection) request.getSession().getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
//        if (null == simplePrincipalCollection) {
//            redisTemplate.expire(key, 30, TimeUnit.SECONDS);
//            return;
//        }
//        LoginInfoDTO loginInfoDTO = (LoginInfoDTO) simplePrincipalCollection.getPrimaryPrincipal();
//        if (null == loginInfoDTO || null == loginInfoDTO.getId()) {
//            System.out.println(JsonUtils.obj2Str("update expire"));
//            redisTemplate.expire(key, 30, TimeUnit.SECONDS);
//
//        }
//
//    }
//}
